package Util;

import com.zk.po.User;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;


import java.util.Date;


public class CreateJwt {

    public String getoken(@NotNull User user) {
        //Jwts.builder();//生成
        //Jwts.parser();//解密

        JwtBuilder jwtBuilder = Jwts.builder()
                .setId(user.getId() + "")//设置需要加密的内容
                .setSubject(user.getUsername())
                .setIssuedAt(new Date())//token保留时间
                .signWith(SignatureAlgorithm.HS256, "my-123")
                .setExpiration(new Date(new Date().getTime() + 43200000));
        System.out.println(jwtBuilder.compact());
        return jwtBuilder.compact();
    }

    //@Test
    //public void test() {
    //    //Jwts.builder();//生成
    //    //Jwts.parser();//解密
    //    User user =  new User();
    //    user.setId("02127681ea0111eca5af971fd4cb7d11");
    //    user.setUsername("seea");
    //    JwtBuilder jwtBuilder = Jwts.builder()
    //            .setId(user.getId())//设置需要加密的内容
    //            .setSubject(user.getUsername())
    //            .setIssuedAt(new Date())//token保留时间
    //            .signWith(SignatureAlgorithm.HS256, "my-123")
    //            .setExpiration(new Date(new Date().getTime() + 43200000));
    //    System.out.println(jwtBuilder.compact());
    //}
}
